<template>
  <div id="china" class="pt" :class="{ h5: this.$store.state.webType === 'h5' }">
    <el-row :span="24" class="page-content">
      <div class="publish_events_box">
        <div class="publish_events_box_title">Publish Events</div>
        <div class="publish_events_box_form">
          <el-form
            :model="ruleForm"
            :rules="rules"
            ref="ruleForm"
            label-width="100px"
            class="demo-ruleForm"
          >
            <el-form-item label="Title" prop="title">
              <el-input v-model="ruleForm.title"></el-input>
            </el-form-item>
            <el-form-item label="Type" prop="label">
              <el-select v-model="ruleForm.label">
                <el-option label="WFUCA Events" value="100"></el-option>
                <el-option label="Other Events" value="101"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="Country" prop="country">
              <el-input v-model="ruleForm.country"></el-input>
            </el-form-item>
            <el-form-item label="Location" prop="location">
              <el-input v-model="ruleForm.location"></el-input>
            </el-form-item>
            <el-form-item label="Data & Time" required prop="time">
              <el-input v-model="ruleForm.time"></el-input>
            </el-form-item>
            <el-form-item label="Banner" prop="coverImg">
              <!--   :action="this.$api + '/un/file/upload'"-->
              <el-upload
                class="upload-demo"
                action="https://jsonplaceholder.typicode.com/posts/"
                drag
                multiple
                :file-list="uploadList"
                :http-request="uploadURL"
                :before-upload="handleBeforeUpload"
                :limit="1"
                :on-remove="handleRemove"
                ref="fileupload"
              >
                <i class="el-icon-upload"></i>
                <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                <div class="el-upload__tip" slot="tip">只能上传jpg/png文件，且不超过500kb</div>
              </el-upload>
            </el-form-item>
            <el-form-item label="Brief" prop="brief">
              <el-input type="textarea" v-model="ruleForm.brief"></el-input>
            </el-form-item>
            <el-form-item label="Need online" prop="isActivity">
              <el-radio-group v-model="ruleForm.isActivity">
                <el-radio label="Yes"></el-radio>
                <el-radio label="No"></el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="Information" prop="activityInformation">
              <el-checkbox-group v-model="ruleForm.activityInformation">
                <el-checkbox label="Name" name="type"></el-checkbox>
                <el-checkbox label="Gender" name="type"></el-checkbox>
                <el-checkbox label="country" name="type"></el-checkbox>
                <el-checkbox label="E-mail" name="type"></el-checkbox>
                <el-checkbox label="Contact Number" name="type"></el-checkbox>
                <el-checkbox label="ORG-name" name="type"></el-checkbox>
              </el-checkbox-group>
            </el-form-item>
            <el-form-item label="Event Description" prop="content">
              <tinymce
                :width="700"
                :height="200"
                v-model="ruleForm.content"
                ref="tinymce"
              ></tinymce>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" class="sub_btn_form" @click="submitForm('ruleForm')"
                >submit</el-button
              >
              <el-button @click="resetForm('ruleForm')">重置</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </el-row>
  </div>
</template>

<script>
import HotArticle from "@/components/HotArticle";
import NewBook from "@/components/NewBook";
import Tinymce from "@/components/tinymce";

export default {
  name: "china",
  components: {
    HotArticle,
    NewBook,
    Tinymce,
  },
  data() {
    return {
      busy: true,
      nomore: false,
      gutterWidth: 20,
      uploadList: [],
      bannerHeight: 0, // 轮播图容器高度;
      screenWidth: 0,
      bannerList: [],

      currentLabel: "",
      currentView: "img",
      bannerData: {},
      bookData: {},
      articleData: [],
      // 文章列表
      artData: [],
      // 文章总数量
      listTotal: 0,
      maxPage: 1,
      // 文章列表请求信息
      listQuery: {
        columnId: "",
        labelId: "",
        pageSize: 10,
        pageNum: 1,
      },
      // 标签
      labelData: [],
      ruleForm: {
        title: "",
        country: "",
        time: "",
        activityInformation: [],
        label: "",
        content: "",
        location: "",
        coverImage: "",
        isActivity: "",
        language: "",
        token: "",
      },
      rules: {
        title: [{ required: true, message: "请输入活动名称", trigger: "blur" }],
        region: [{ required: true, message: "请选择活动区域", trigger: "change" }],
        date1: [{ type: "date", required: true, message: "请选择日期", trigger: "change" }],
        date2: [{ type: "date", required: true, message: "请选择时间", trigger: "change" }],
        desc: [{ required: true, message: "请填写活动形式", trigger: "blur" }],
      },
    };
  },
  mounted() {
    if (this.$route.query.token) {
      sessionStorage.setItem("token", this.$route.query.token);
    }
    this.listQuery.columnId = this.$getPartId(this.$route.path);
    this.listQuery.menuId = this.$getMenuId(this.$route.path);
    // this.getList();
    // this.getBanner();
    // this.getLabels();
    // 首次加载时,初始化高度
    this.screenWidth = window.innerWidth;
    this.bannerHeight = (748 / 1920) * this.screenWidth;
    // 窗口大小发生改变
    window.onresize = () => {
      this.screenWidth = window.innerWidth;
      this.bannerHeight = (748 / 1920) * this.screenWidth;
    };
  },
  methods: {
    handleBeforeUpload(file) {
      console.log(file);
      this.fileType = file.name.split(".")[1];
    },
    uploadURL(file) {
      console.log(file, "file");
      const formData = new FormData();
      formData.append("file", file.file);
      console.log(formData, "formData");
      //注意哦，这里指定文件夹'image/'，尝试过写在配置文件，但是各种不行，写在这里就可以
      var fileName = "video/" + "ymy_" + `${Date.parse(new Date())}` + "." + this.fileType;
      let pageName = file.file.name;
      console.log(pageName);
      // this.videoFlag = true;
      let that = this;
      this.$post(this.$api + "/web/common/upload", formData).then((res) => {
        this.ruleForm.coverImage = res.url;
      });
      return;
      //定义唯一的文件名，打印出来的uid其实就是时间戳
      client()
        .multipartUpload(fileName, file.file, {
          headers,
          progress: function (percentage, cpt) {
            console.log("打印进度", percentage);
            console.log(that.videoFlag);
            that.videoUploadPercent = parseInt(percentage * 100);
          },
        })
        .then((res) => {
          console.log(res);
          //此处赋值，是相当于上传成功之后，手动拼接服务器地址和文件名
          this.form.imgUrl = res.res.requestUrls[0].split("?")[0];
          this.uploadList = [{ name: pageName, url: this.form.imgUrl }];
          console.log(this.uploadList);
          this.$message.success("作品上传成功！");
          // 进度条恢复到初始状态
          this.videoFlag = false;
          this.videoUploadPercent = 0;
        });
    },
    handleRemove: function (file, fileList) {
      this.uploadList = [];
    },
    submitForm(formName) {
      this.ruleForm.language = localStorage.getItem("lang");
      this.ruleForm.token = sessionStorage.getItem("tokenPub");
      this.$refs[formName].validate((valid) => {
        console.log(this.ruleForm, "ruleForm-->");
        if (valid) {
          this.$post(this.$api + "/un/webnews/addevents", this.ruleForm).then((res) => {
            this.$message({
              message:
                this.$store.state.lang == "FR" ? "Soumettre avec succès!" : "Submit Success！",
              type: "success",
            });
            this.$router.push("/publishlist");
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    async loadMore() {
      // console.log(
      //   "loadMore",
      //   this.busy || this.listQuery.pageNum >= this.maxPage
      // );
      if (this.busy || this.listQuery.pageNum >= this.maxPage) return;
      this.busy = true;
      this.listQuery.pageNum += 1;
      await this.getList();
    },
    getList() {
      this.$get(this.$api + "/cms/web/selsctWeb", this.listQuery).then((res) => {
        this.artData = [...this.artData, ...res.data];
        this.listTotal = res.total;
        this.maxPage = res.maxPage;

        let that = this;
        this.$nextTick(() => {
          that.nomore = true;
          setTimeout(() => {
            that.busy = false;
          }, 300);
        });
      });
    },
    changeLabel(id, label) {
      this.listQuery.labelId = id;
      this.listQuery.pageNum = 1;
      this.currentLabel = label;
      this.artData = [];
      this.getList();
    },
    getLabels() {
      this.$get(this.$api + "/cms/web/getLabelByPartId", {
        partId: this.listQuery.columnId,
      }).then((res) => {
        this.labelData = res.data;
      });
    },
    getListMore() {
      this.listQuery.pageNum += 1;
      this.getList();
    },
    getBanner() {
      this.$get(this.$api + "/cms/web/partArticleBanner", {
        menuId: this.listQuery.menuId,
      }).then((res) => {
        res.data.list.forEach((item) => {
          this.bannerList.push(item);
        });
        this.bannerData = res.data.banner[0];
        //  console.log(this.bannerList, this.bannerData);
      });
    },
    viewTypeChange(type) {
      this.artData = [];
      this.listQuery.pageNum = 1;
      this.getList();
      this.currentView = type;
      this.$nextTick(() => {
        this.$redrawVueMasonry();
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.sub_btn_form {
  background-color: rgba(0, 93, 176, 1);
  border-radius: 35px;
  height: 49px;
  width: 307px;
}
#china {
  position: relative;
  width: 100%;

  &::after {
    // content: "";
    position: absolute;
    left: 0;
    top: 0;
    z-index: -1;
    width: 100%;
    height: 100%;
    background: url("../assets/images/ddzg-bg.jpg") no-repeat;
    background-size: 100% auto;
    background-position: center 0;
  }

  .page {
    padding: fh(152vh, pc) fw(80vw, pc) 0 fw(80vw, pc);
    background: #fff;

    ::v-deep .el-breadcrumb {
      // margin-left: fw(-40vw, pc);
      .el-breadcrumb__inner {
        font-weight: bold;
        color: #fff !important;
        font-size: fh(18vh, pc);
      }
    }
  }

  .page-content {
    padding: 0 fw(80vw, pc) fh(40vh, pc) fw(80vw, pc);
    background-color: #fff;
  }

  .art-row {
    display: flex;
    margin-top: fh(40vh, pc);
    width: 100%;

    .book-content {
      background-color: $fh90;
      padding-bottom: fh(40vh, pc);

      .book-btn {
        display: flex;
        width: 100%;
        align-items: flex-end;
        justify-content: center;

        img {
          width: fw(180vw, pc);

          &:hover {
            cursor: pointer;
            opacity: 0.7;
          }
        }
      }

      .book-row {
        display: flex;
        width: 100%;
        padding: fh(46vh, pc) fw(20vw, pc);
        color: $sh;

        img.book-img {
          width: fw(280vw, pc);
        }

        .book-text {
          padding-left: fw(10vw, pc);

          .view-label {
            color: $zh;
            position: relative;
            display: inline-block;
            font-size: fh(24vh, pc);
            font-weight: 800;
            margin-top: fh(20vh, pc);
            margin-bottom: fh(60vh, pc);

            &::after {
              content: "";
              position: absolute;
              bottom: fh(-16vh, pc);
              right: fw(-12vw, pc);
              width: fw(30vw, pc);
              height: fh(18vh, pc);
              border-right: fw(6vw, pc) solid hsla(14, 74%, 37%, 0.2);
              border-bottom: fw(8vw, pc) solid hsla(14, 74%, 37%, 0.2);
            }
          }

          .text-item {
            padding-bottom: fh(30vh, pc);

            .item-title {
              color: $sh;
              font-size: fh(18vh, pc);
              font-weight: bold;
              padding-bottom: fh(20vh, pc);
            }

            .item-content {
              font-size: fh(16vh, pc);
              line-height: fh(26vh, pc);
            }
          }
        }
      }
    }

    .row-right {
      display: flex;
      flex: 1;
      margin-left: fw(20vw, pc);
      flex-flow: column;

      .hot-article {
        width: 100%;
        padding: fh(30vh, pc) fw(30vw, pc);
        background-color: $fh90;
        margin-top: 0;

        .article-label {
          color: $zh;
          position: relative;
          display: inline-block;
          font-size: fh(24vh, pc);
          font-weight: 800;
          margin-top: fh(20vh, pc);
          margin-bottom: fh(60vh, pc);

          &::after {
            content: "";
            position: absolute;
            bottom: fh(-16vh, pc);
            right: fw(-12vw, pc);
            width: fw(30vw, pc);
            height: fh(18vh, pc);
            border-right: fw(6vw, pc) solid hsla(14, 74%, 37%, 0.2);
            border-bottom: fw(8vw, pc) solid hsla(14, 74%, 37%, 0.2);
          }
        }

        .article-view {
          color: $sh;

          .article-item {
            width: fw(485vw, pc);
            line-height: fh(26vh, pc);
            margin-bottom: fh(26vh, pc);
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;

            span {
              color: $zh;
              font-size: fh(18vh, pc);
              font-weight: bold;
              display: inline-block;
              padding-right: fw(16vw, pc);
            }

            &:hover {
              opacity: 0.8;
              cursor: pointer;
              color: $zh;
            }
          }
        }
      }
    }
  }

  .art-col {
    position: relative;
    width: fw(1180vw, pc);
    margin-top: fh(20vh, pc);

    .art-tab {
      width: 100%;
      display: flex;
      align-items: center;
      margin-bottom: fh(30vh, pc);
      color: $sh;

      .tab-item {
        margin-right: fw(60vw, pc);
        font-size: fh(16vh, pc);
        position: relative;
        line-height: fh(24vh, pc);

        &:hover {
          color: $sh;
          cursor: pointer;
        }

        &.active {
          font-size: fh(20vh, pc);
          font-weight: bold;
          color: $sh;

          &::before {
            content: "";
            position: absolute;
            bottom: fh(-14vh, pc);
            width: 100%;
            border-top: fh(6vh, pc) solid $zh;
          }
        }
      }

      .tab-info {
        margin-left: auto;
        display: flex;
        align-items: center;

        .toggle-img {
          margin-left: fh(62vw, pc);
          margin-right: fh(24vw, pc);
        }

        img {
          width: fw(20vw, pc);
          cursor: pointer;
        }
      }
    }

    .art-view {
      cursor: pointer;

      &.text {
        .art-item {
          width: 100%;
        }

        .item-title {
          color: $sh;
          display: flex;
          width: 100%;

          .item-info {
            padding-left: fw(40vw, pc);
            margin-left: auto;
            width: max-content !important;

            .info-label {
              margin-right: fw(20vw, pc);
              width: max-content !important;
            }

            .info-time {
              width: max-content;
              margin-left: fw(20vw, pc) !important;
            }
          }
        }
      }

      .art-item {
        // break-inside: avoid;
        width: calc((100% - 40px) / 3);
        margin-bottom: fh(20vh, pc);
        background-color: $dh;

        &:hover {
          opacity: 0.9;
        }

        img {
          width: 100%;
        }

        .art-content {
          width: 100%;
          color: rgba(251, 254, 255, 0.8);
          padding: fh(20vh, pc) fw(20vw, pc);
          position: relative;
          z-index: 2;
          background-color: $dh;

          .item-title {
            color: $sh;
            font-size: fh(16vh, pc);
            line-height: fh(22vh, pc);
            margin-bottom: fh(8vh, pc);
            font-weight: 600;
          }

          .item-info {
            display: flex;
            align-items: center;
            justify-content: space-between;
            // margin-bottom: fh(12vh, pc);
            font-size: fh(14vh, pc);
            line-height: fh(20vh, pc);

            .info-time {
              color: #a1b8bd;
              margin-left: auto;
            }
          }

          .item-content {
            font-size: fh(14vh, pc);
            line-height: fh(20vh, pc);
            font-weight: 400;
            width: 100%;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
        }
      }
    }

    .art-more {
      width: max-content;
      margin: fh(40vh, pc) auto;
      color: $sh;
      font-size: fh(14vh, pc);

      &.true:hover {
        cursor: pointer;
        opacity: 0.8;
        color: $zh;
      }

      &.none {
        opacity: 0.5;
      }
    }
  }

  .banner-view {
    display: flex;
    width: 100%;
    margin-top: fh(16vh, pc);

    .content-view {
      position: absolute;
      left: 0;
      bottom: 0;
      width: 100%;
      padding: fh(20vh, pc) fw(40vw, pc);
      padding-bottom: fh(40vh, pc);
      background: linear-gradient(180deg, rgba(34, 0, 0, 0.3) 0%, $sh 100%);
      color: #fff;

      .content-title {
        font-size: fh(20vh, pc);
        line-height: fh(30vh, pc);
        margin-bottom: fh(12vh, pc);
      }

      .content-text {
        font-size: fh(14vh, pc);
        line-height: fh(23vh, pc);
        height: fh(46vh, pc);
      }
    }

    .banner-col {
      position: relative;
      width: fw(1180vw, pc);
      margin-right: fw(20vw, pc);
      cursor: pointer;
      opacity: 0.9;

      .col-text {
        display: flex;
        align-items: center;

        .text-item {
          flex: 1;
          color: #fff;
          padding: fh(20vh, pc) fw(20vw, pc);
          background-color: $dh;
          font-size: fh(16vh, pc);
          line-height: fh(24vh, pc);
          margin: 0 fw(2vw, pc);

          &.active {
            background-color: $zh;
          }

          &:nth-child(1) {
            margin-left: 0;
          }

          &:nth-last-child(1) {
            margin-right: 0;
          }

          &:hover {
            opacity: 0.8;
            cursor: pointer;
          }
        }
      }

      .banner-big {
        width: 100%;
        display: block;
      }
    }

    .int-col {
      position: relative;
      width: fw(560vw, pc);
      background-color: rgba(15, 0, 0, 0.5);
      cursor: pointer;
      opacity: 0.9;

      > img {
        width: 100%;
      }

      .int-content {
        padding: fh(20vh, pc) fw(20vw, pc);

        .content-title {
          font-size: fh(24vh, pc);
          font-weight: 800;
          color: #a1b8bd;
          line-height: fh(35vh, pc);
        }

        .content-import {
          margin-top: fh(40vh, pc);
          position: relative;
          color: #d6d6d6;
          padding: fh(24vh, pc) fw(20vw, pc);
          padding-bottom: fh(16vh, pc);
          background-color: rgba(255, 255, 255, 0.5);
          font-size: fh(16vh, pc);
          font-weight: 800;
          line-height: fh(24vh, pc);

          &::before {
            content: "“";
            font-family: cursive;
            position: absolute;
            font-size: fh(60vh, pc);
            left: fh(-20vw, pc);
            top: fh(5vh, pc);
            color: $zh;
          }

          &::after {
            content: "”";
            font-family: cursive;
            position: absolute;
            font-size: fh(60vh, pc);
            right: fh(-20vw, pc);
            bottom: fh(-24vh, pc);
            color: $zh;
          }
        }

        .content-html {
          margin-top: fh(50vh, pc);

          p {
            font-size: fh(14vh, pc);
            font-family: "宋体";
            font-weight: 400;
            color: rgba(255, 255, 255, 0.8);
            line-height: fh(20vh, pc);
            margin-top: fh(26vh, pc);
          }

          .html-title {
            font-size: fh(16vh, pc);
            font-weight: bold;
            color: #ffffff;
            line-height: fh(24vh, pc);
          }
        }
      }

      .label-view {
        display: flex;
        width: 100%;
        justify-content: space-between;
        align-items: center;
        color: #fff;
        padding: fh(40vh, pc) fw(20vw, pc) fh(28vh, pc) fw(20vw, pc);
        border-bottom: 1px solid #fff;

        .int-label {
          color: #d6d6d6;
          position: relative;
          display: inline-block;
          font-size: fh(24vh, pc);
          font-weight: 800;

          &::after {
            content: "";
            position: absolute;
            bottom: fh(-16vh, pc);
            right: fw(-12vw, pc);
            width: fw(30vw, pc);
            height: fh(18vh, pc);
            border-right: fw(6vw, pc) solid #d6d6d6;
            border-bottom: fw(8vw, pc) solid #d6d6d6;
          }
        }

        .int-more {
          font-size: fh(14vh, pc);
          font-weight: 600;
          line-height: fh(20vh, pc);
          color: rgba(255, 255, 255, 0.5);

          &:hover {
            cursor: pointer;
            color: #fff;
          }
        }
      }
    }
  }
}

#china.h5 {
  &::after {
    background-size: auto;
  }

  .banner-view {
    flex-wrap: wrap;

    .banner-col {
      width: 100%;
      margin-bottom: fh(20vh, h5);
    }

    .int-col {
      width: 100%;
    }

    .content-view {
      padding: 10px;
      bottom: -2px;
      z-index: 2;

      .content-title {
        margin-bottom: 6px;
      }

      .content-text {
        display: none;
      }
    }
  }

  .art-col .art-view {
    &.text {
      .art-item {
        width: 100%;
      }
    }

    .art-item {
      width: calc(50% - 10px);
      margin-bottom: fw(8vw, h5);

      .art-content {
        padding: fw(8vw, h5) !important;
      }
    }
  }
}
.publish_events_box {
  margin: 0 auto;
  margin-top: 30px;
  width: 84%;
  .publish_events_box_title {
    height: 49px;
    overflow-wrap: break-word;
    color: rgba(0, 93, 176, 1);
    font-size: 32px;
    font-family: "SourceHanSansCN-Medium";
    font-weight: 500;
    text-align: left;
    white-space: nowrap;
    line-height: 48px;
    border-bottom: 1px solid #ccc;
  }
  .publish_events_box_form {
    padding: 30px 227px 0 64px;
  }
}
</style>
